﻿using System;

namespace shape
{
    public abstract class Shape
    {
        abstract public void Area();
        abstract public bool IsLegal();
        public double length;
        public double Length
        {
            get { return length; }
            set { length = value; }
        }
        public double height;
        public double Height
        {
            get { return height; }
            set
            {
                height = value;
            }
        }
      
    }
    public class Triangle : Shape
    {
        double a, b,c;
        public override void Area()
        {
            double sum = 0;
            Console.WriteLine("输入三角形一条边：");
            Length = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入此边上的高：");
            Height = double.Parse(Console.ReadLine());
            sum = Length * Height * 0.5;
            Console.WriteLine("The triangle's area:" + sum + "");

        }

        public override bool IsLegal()
        {
            Console.WriteLine("Please Enter the first edge of the triangle:");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("The second:");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("The third:");
            c = double.Parse(Console.ReadLine());
            if ((a + b > c) & (a + c > b) & (b + c > a))
                return true;
            return false;
        }
    }
    public class Square : Shape
    {
        double a, b, c, d;
        public override void Area()
        {
            double sum = 0;
            Console.WriteLine("输入正方形一条边：");
            Length = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入此边上的高：");
            Height = double.Parse(Console.ReadLine());
            sum = Length * Height ;
            Console.WriteLine("The square's area:" + sum + "");
        }
        public override bool IsLegal()
        {
            Console.WriteLine("Please Enter the first edge of the triangle:");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("The second:");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("The third:");
            c = double.Parse(Console.ReadLine());
            Console.WriteLine("The forth:");
            d = double.Parse(Console.ReadLine());
            if ((a == b) & (b == c) & (c == d) & (d == a))
                return true;
            return false;
        }
    }
    public class Rectangle : Shape
    {
        double a, b, c, d;
        public override void Area()
        {
            double sum = 0;
            Console.WriteLine("输入长方形一条边：");
            Length = double.Parse(Console.ReadLine());
            Console.WriteLine("请输入此边上的高：");
            Height = double.Parse(Console.ReadLine());
            sum = Length * Height;
            Console.WriteLine("The rectangle's area:" + sum + "");
        }
        public override bool IsLegal()
        {
            Console.WriteLine("输入长方形一条边:");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("输入其对边:");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("输入上两条边外的第三条边:");
            c = double.Parse(Console.ReadLine());
            Console.WriteLine("输入其对边:");
            d = double.Parse(Console.ReadLine());
            if ((a == b) & (c == d)) { return true; }
            return false;
        }
    }
    class test
    {
        public static void Main(string[] args)
        {
            Triangle test1 = new Triangle();
            test1.Area();
            bool legal1=test1.IsLegal();
            if (legal1) { Console.WriteLine("legal!"); } else { Console.WriteLine("illegal!"); }
            Square test2 = new Square();
            test2.Area();
            bool legal2= test2.IsLegal();
            if (legal2) { Console.WriteLine("legal!"); } else { Console.WriteLine("illegal!"); }
            Rectangle test3 = new Rectangle();
            test3.Area();
            bool legal3 = test3.IsLegal();
            if (legal3) { Console.WriteLine("legal!"); } else { Console.WriteLine("illegal!"); }
        }
    }
}



